#pragma once

#include "Entity.h"

//void GenerateIndexedCube(IDirect3DVertexBuffer9 *vb, IDirect3DIndexBuffer9 *ib, float nWidth, float nHeight, float nDepth);
void DeclareVertexDecl( void );
void DeleteVertexDecl( void );

struct Vertex
{
	D3DXVECTOR3 position;
	D3DXVECTOR3 normal;
	D3DXVECTOR2 texCoord;

	static IDirect3DVertexDeclaration9* Decl;

	Vertex()
	{
		position = D3DXVECTOR3(0,0,0);
		normal = D3DXVECTOR3(0,0,0);
		texCoord = D3DXVECTOR2(0,0);
	}

	Vertex(D3DXVECTOR3 nPosition, D3DXVECTOR3 nNormal, D3DXVECTOR2 nTexCoord)
	{
		position = nPosition;
		normal = nNormal;
		texCoord = nTexCoord;
	}

	Vertex(float nX, float nY, float nZ, D3DXCOLOR nColor, float nU, float nV)
	{
		position = D3DXVECTOR3(nX, nY, nZ);
		normal.x = nColor.r;
		normal.y = nColor.g;
		normal.z = nColor.b;
		texCoord = D3DXVECTOR2(nU, nV);

	}
};

struct BaseMeshEntity : public Entity
{
public:
	IDirect3DDevice9 *Device;
	ID3DXMesh *Mesh;
	D3DMATERIAL9 *Material;
	IDirect3DTexture9 **Texture;
	DWORD numMaterials;

	BaseMeshEntity();
	BaseMeshEntity(IDirect3DDevice9 *nDevice);
	~BaseMeshEntity();

	virtual void Update( float dt);
	virtual void Render( void );
	
	virtual void onLostDevice( void );
	virtual void onResetDevice( void );

	HRESULT LoadXFile( std::string Filename, DWORD Options );

};

struct BaseGraphicalEntity : public Entity
{
public:
	IDirect3DDevice9 *Device;
	IDirect3DVertexBuffer9 *VertexBuffer;
	unsigned int numVertices;
	/*D3DMATERIAL9 *Material;
	LPDIRECT3DTEXTURE9 *Texture;
	DWORD numMaterials;*/
	
	BaseGraphicalEntity();
	BaseGraphicalEntity(IDirect3DDevice9 *nDevice);
	~BaseGraphicalEntity();

	virtual void Update( float dt);
	virtual void Render( void );

	virtual void onLostDevice( void );
	virtual void onResetDevice( void );

	//A TEST FUNCTION
	bool CreateQuad( D3DXVECTOR3 halfVector);
	
};

struct BaseIndexedGraphicalEntity : public BaseGraphicalEntity
{
public:
	IDirect3DIndexBuffer9 *IndexBuffer;
	unsigned int numIndices;

	//D3DMATERIAL9 *Material;
	IDirect3DTexture9 *Texture;
	//DWORD numMaterials;
	
	BaseIndexedGraphicalEntity();
	BaseIndexedGraphicalEntity(IDirect3DDevice9 *nDevice);
	~BaseIndexedGraphicalEntity();

	virtual void Update( float dt);
	virtual void Render( void );

	virtual void onLostDevice( void );
	virtual void onResetDevice( void );

	virtual bool CreateCube(D3DXVECTOR3 HalfVector);
	virtual bool CreateCube(D3DXVECTOR3 HalfVector, D3DXCOLOR nColor);
	
};

bool DoesTextureExist(std::string FileName);
UINT GetTextureNumber(std::string FileName);
void ClearString(char* ClearMe, UINT size);

bool DoesModelExist(std::string FileName);
UINT GetModelNumber(std::string FileName);
